package com.zxq.ruoyi.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.github.pagehelper.PageInfo;
import com.zxq.ruoyi.domain.IotPacket;
import com.zxq.ruoyi.domain.vo.PacketFieldVoInfo;
import com.zxq.ruoyi.service.impl.IotPacketServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.zxq.ruoyi.domain.IotPacketField;
import com.zxq.ruoyi.service.IIotPacketFieldService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 数据包-字段Controller
 * 
 * @author ruoyi
 * @date 2022-09-14
 */
@RestController
@RequestMapping("/packetField")
public class IotPacketFieldController extends BaseController
{
    @Autowired
    private IIotPacketFieldService iotPacketFieldService;

    @Autowired
    private IotPacketServiceImpl iotPacketService;

    /**
     * 查询数据包-字段列表
     */
    @RequiresPermissions("iot:packetField:list")
    @GetMapping("/list")
    public PacketFieldVoInfo list(IotPacketField iotPacketField)
    {
        startPage();
        List<IotPacketField> list = iotPacketFieldService.selectIotPacketFieldList(iotPacketField);
        PacketFieldVoInfo rspData = new PacketFieldVoInfo();
        rspData.setCode(200);
        rspData.setRows(list);
        rspData.setPacketList(iotPacketService.selectIotPacketList(new IotPacket()));
        rspData.setMsg("查询成功");
        rspData.setTotal((new PageInfo(list)).getTotal());

        return rspData;
    }

    /**
     * 导出数据包-字段列表
     */
    @RequiresPermissions("iot:packetField:export")
    @Log(title = "数据包-字段", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IotPacketField iotPacketField)
    {
        List<IotPacketField> list = iotPacketFieldService.selectIotPacketFieldList(iotPacketField);
        ExcelUtil<IotPacketField> util = new ExcelUtil<IotPacketField>(IotPacketField.class);
        util.exportExcel(response, list, "数据包-字段数据");
    }

    /**
     * 获取数据包-字段详细信息
     */
    @RequiresPermissions("iot:packetField:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(iotPacketFieldService.selectIotPacketFieldById(id));
    }

    /**
     * 新增数据包-字段
     */
    @RequiresPermissions("iot:packetField:add")
    @Log(title = "数据包-字段", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody IotPacketField iotPacketField)
    {
        return toAjax(iotPacketFieldService.insertIotPacketField(iotPacketField));
    }

    /**
     * 修改数据包-字段
     */
    @RequiresPermissions("iot:packetField:edit")
    @Log(title = "数据包-字段", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody IotPacketField iotPacketField)
    {
        return toAjax(iotPacketFieldService.updateIotPacketField(iotPacketField));
    }

    /**
     * 删除数据包-字段
     */
    @RequiresPermissions("iot:packetField:remove")
    @Log(title = "数据包-字段", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(iotPacketFieldService.deleteIotPacketFieldByIds(ids));
    }
}
